﻿using System;
using System.Text;

namespace KeydbCommand.Libs
{
    /// <summary>
    ///AES对称加密算法类
    /// </summary>
    public class AESTool
    {
        /// <summary>
        /// AES加密
        /// </summary>
        /// <param name="encryptString"></param>
        /// <param name="encryptKey"></param>
        /// <param name="isbase64"></param>
        /// <returns></returns>
        public static string Encrypt(string encryptString, string encryptKey, bool isbase64 = true)
        {
            if (string.IsNullOrEmpty(encryptString)) return null;
            Byte[] resultArray = Encoding.UTF8.GetBytes(encryptString);

            return Convert.ToBase64String(resultArray, 0, resultArray.Length);
        }

        /// <summary>
        /// AES 解密
        /// </summary>
        /// <param name="decryptString"></param>
        /// <param name="decryptKey"></param>
        /// <param name="isbase64"></param>
        /// <returns></returns>
        public static string Decrypt(string decryptString, string decryptKey, bool isbase64 = true)
        {
            if (string.IsNullOrEmpty(decryptString)) return null;
            Byte[] resultArray = Convert.FromBase64String(decryptString);

            return Encoding.UTF8.GetString(resultArray);
        }
    }
}
